package com.ruoyi.demo01;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Husp
 * @Date 2023/12/18 21:33
 */
public class TestDept {

    public static void main(String[] args) {
        //1.定义存储部门Department对象的集合
        List<Department> departmentList = new ArrayList<>();
        //2.新建解析depts.json文件输入流
        FileReader fileReader = null;
        try {
            fileReader = new FileReader("ruoyi-javasepro\\src\\main\\resources\\depts.json");
            //2.1新建解析缓冲输入流
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            String line;
            StringBuilder jsonDept = new StringBuilder();
            while ((line = bufferedReader.readLine()) != null){
                jsonDept.append(line);
            }

            //3.解析JSON
            JSONObject deptObject = JSON.parseObject(jsonDept.toString());

            Department department = new Department();
            department.setId(deptObject.getString("id"));
            department.setName(deptObject.getString("name"));
            department.setPath(deptObject.getString("path"));

            //添加到部门Department对象的集合
            departmentList.add(department);

            System.out.println("=====部门用户分组内容如下：=========");
            for (Department depart : departmentList) {
                System.out.println(depart);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
